
# week.information
  if ("AGE" %in% option[[i]]){
    select.information <- c(group.begin[j], group.avg[j], group.end[j], length(original.cases[,1]))
  } else {select.information <- c(week.begin[j], week[j], week.end[j], length(original.cases[,1]))}

# dfd.avg
dfd.avg <- mean(original.cases$dfdgg10.a)

# sample.age.attributes 
ego.age.avg <- mean(original.cases$age.gg10.e)
ego.age.lowquart <- unname(summary(original.cases$age.gg10.e))[2]
ego.age.median <- unname(summary(original.cases$age.gg10.e))[3]
ego.age.highquart <- unname(summary(original.cases$age.gg10.e))[5]
alter.age.avg <- mean(original.cases$age.gg10.a)
alter.age.lowquart <- unname(summary(original.cases$age.gg10.a))[2]
alter.age.median <- unname(summary(original.cases$age.gg10.a))[3]
alter.age.highquart <- unname(summary(original.cases$age.gg10.a))[5]
age.at.death <- mean(original.cases$ageatdeath.a)
ea.agediscrep.avg <- mean(original.cases$ea.agediscrep)
ea.agediscrep.median <- median(original.cases$ea.agediscrep)

sample.age.attributes <- c(ego.age.avg, ego.age.lowquart, ego.age.median, ego.age.highquart, alter.age.avg, alter.age.lowquart, alter.age.median, alter.age.highquart, age.at.death, ea.agediscrep.avg, ea.agediscrep.median)

# sample.occupancy.attributes 
hid.occnum.avg <- mean(original.cases$hid.occnum)
hid.occnum.median <- median(original.cases$hid.occnum)

sample.occupancy.attributes <- c(hid.occnum.avg, hid.occnum.median)

# sample.turnout.attributes 
turnout.gg10 <- mean(original.cases$gg10.e)
turnout.gp10 <- mean(original.cases$gp10.e)
turnout.ss9 <- mean(original.cases$ss9.e)
turnout.pg8 <- mean(original.cases$pg8.e)
turnout.pp8 <- mean(original.cases$pp8.e)
turnout.gg6 <- mean(original.cases$gg6.e)
turnout.gp6 <- mean(original.cases$gp6.e)
turnout.ss5 <- mean(original.cases$ss5.e)
turnout.pg4 <- mean(original.cases$pg4.e)

turnout.pg8.alter <- mean(original.cases$pg8.a)
turnout.gg6.alter <- mean(original.cases$gg6.a)
turnout.gp6.alter <- mean(original.cases$gp6.a)
turnout.ss5.alter <- mean(original.cases$ss5.a)
turnout.pg4.alter <- mean(original.cases$pg4.a)

sample.turnout.attributes <- c(turnout.gg10, turnout.gp10, turnout.ss9, turnout.pg8, turnout.pp8, turnout.gg6, turnout.gp6, turnout.ss5, turnout.pg4, turnout.pg8.alter, turnout.gg6.alter, turnout.gp6.alter, turnout.ss5.alter, turnout.pg4.alter)

# sample.gender.attributes 
female.to.male <- table(original.cases$female.e)[2]/table(original.cases$male.e)[2]
female.ego.age.avg <- mean(original.cases[original.cases$female.e==1,]$age.gg10.e)
female.ego.age.median <- median(original.cases[original.cases$female.e==1,]$age.gg10.e)
female.alter.avg <- mean(original.cases[original.cases$female.a==1,]$age.gg10.a)
female.alter.age.median <- median(original.cases[original.cases$female.a==1,]$age.gg10.a)
female.egos <- length(original.cases[original.cases$female.e==1,]$age.gg10.e)
female.alters <- length(original.cases[original.cases$female.a==1,]$age.gg10.a)
male.ego.age.avg <- mean(original.cases[original.cases$male.e==1,]$age.gg10.e)
male.ego.age.median <- median(original.cases[original.cases$male.e==1,]$age.gg10.e)
male.alter.age.avg <- mean(original.cases[original.cases$male.a==1,]$age.gg10.a)
male.alter.age.median <- median(original.cases[original.cases$male.a==1,]$age.gg10.a)
male.egos <- length(original.cases[original.cases$male.e==1,]$age.gg10.e)
male.alters <- length(original.cases[original.cases$male.a==1,]$age.gg10.a)

sample.gender.attributes <- c(female.to.male, female.ego.age.avg, female.ego.age.median, female.alter.avg, female.alter.age.median, female.egos, female.alters,  male.ego.age.avg, male.ego.age.median, male.alter.age.avg, male.alter.age.median, male.egos, male.alters)

# sample.party.attributes 
ego.dem.to.rep <- table(original.cases$dem.e)[2]/table(original.cases$rep.e)[2]
alter.dem.to.rep <- table(original.cases$dem.a)[2]/table(original.cases$rep.a)[2]
dem.egos <- mean(original.cases$dem.e)
dem.alters <- mean(original.cases$dem.a)
rep.egos <- mean(original.cases$rep.e)
rep.alters <- mean(original.cases$rep.a)

sample.party.attributes <- c(ego.dem.to.rep, alter.dem.to.rep, dem.egos, dem.alters, rep.egos, rep.alters)

# sample.voting.attributes 
same.proportion <- length(original.cases[original.cases$gg6.e==original.cases$gg6.a&original.cases$gp6.e==original.cases$gp6.a& original.cases$ss5.e==original.cases$ss5.a&original.cases$pg4.e==original.cases$pg4.a,]$gg10.e)/length(original.cases$gg10.e)

same.count <- length(original.cases[original.cases$gg6.e==original.cases$gg6.a&original.cases$gp6.e==original.cases$gp6.a& original.cases$ss5.e==original.cases$ss5.a&original.cases$pg4.e==original.cases$pg4.a,]$gg10.e)

more.proportion <- length(original.cases[(original.cases$gg6.e+original.cases$gp6.e+original.cases$ss5.e+original.cases$pg4.e)>(original.cases$gg6.a+original.cases$gp6.a+original.cases$ss5.a+original.cases$pg4.a),]$gg10.e)/length(original.cases$gg10.e)

more.count <- length(original.cases[(original.cases$gg6.e+original.cases$gp6.e+original.cases$ss5.e+original.cases$pg4.e)>(original.cases$gg6.a+original.cases$gp6.a+original.cases$ss5.a+original.cases$pg4.a),]$gg10.e)

fewer.proportion <- length(original.cases[(original.cases$gg6.e+original.cases$gp6.e+original.cases$ss5.e+original.cases$pg4.e)<(original.cases$gg6.a+original.cases$gp6.a+original.cases$ss5.a+original.cases$pg4.a),]$gg10.e)/length(original.cases$gg10.e)

fewer.count <- length(original.cases[(original.cases$gg6.e+original.cases$gp6.e+original.cases$ss5.e+original.cases$pg4.e)<(original.cases$gg6.a+original.cases$gp6.a+original.cases$ss5.a+original.cases$pg4.a),]$gg10.e)

onevote.pg4throughgg6 <- length(original.cases[original.cases$pg4.e + original.cases$ss5.e + original.cases$gp6.e + original.cases$gg6.e==1,]$gg10.e)/length(original.cases$gg10.e)

twovotes.pg4throughgg6 <- length(original.cases[original.cases$pg4.e + original.cases$ss5.e + original.cases$gp6.e + original.cases$gg6.e==2,]$gg10.e)/length(original.cases$gg10.e)

threevotes.pg4throughgg6 <- length(original.cases[original.cases$pg4.e + original.cases$ss5.e + original.cases$gp6.e + original.cases$gg6.e==3,]$gg10.e)/length(original.cases$gg10.e)

fourvotes.pg4throughgg6 <- length(original.cases[original.cases$pg4.e + original.cases$ss5.e + original.cases$gp6.e + original.cases$gg6.e==4,]$gg10.e)/length(original.cases$gg10.e)

novotes.pg4throughgg6 <- length(original.cases[original.cases$pg4.e + original.cases$ss5.e + original.cases$gp6.e + original.cases$gg6.e==0,]$gg10.e)/length(original.cases$gg10.e)

sample.voting.attributes <- c(same.proportion, same.count, more.proportion,more.count, fewer.proportion,fewer.count, onevote.pg4throughgg6, twovotes.pg4throughgg6, threevotes.pg4throughgg6, fourvotes.pg4throughgg6, novotes.pg4throughgg6)

## conditional attributes

if ("pop.density" %in% names(casecontrol) & "percapita.income" %in% names(casecontrol)){
# sample.popdensity.attributes 
pop.density.avg <- mean(original.cases$pop.density)
pop.density.median <- median(original.cases$pop.density)

sample.popdensity.attributes <- c(pop.density.avg, pop.density.median)

# sample.percapitaincome.attributes 
percapita.income.avg <- mean(original.cases$percapita.income)
percapita.income.median <- median(original.cases$percapita.income)

sample.percapitaincome.attributes <- c(percapita.income.avg, percapita.income.median)
}

if ("regdate.e" %in% names(casecontrol) & "regdate.a" %in% names(casecontrol)){
# sample.regdate.attributes 
ego.regdate <- median(original.cases$regdate.e)
alter.regdate <- median(original.cases$regdate.a)

sample.regdate.attributes <- c(ego.regdate, alter.regdate)
}

original.cases.stats <- c(select.information, dfd.avg, sample.age.attributes, sample.occupancy.attributes, sample.turnout.attributes, sample.gender.attributes, sample.party.attributes, sample.voting.attributes)

if ("pop.density" %in% names(casecontrol) & "percapita.income" %in% names(casecontrol)){
  original.cases.stats <- c(original.cases.stats, sample.popdensity.attributes, sample.percapitaincome.attributes)
}

if ("regdate.e" %in% names(casecontrol) & "regdate.a" %in% names(casecontrol)){
  original.cases.stats <- c(original.cases.stats, sample.regdate.attributes)
}
